/**
 * 老板信息完善组件
 */
import React, { Component } from 'react'

import { NavBar, InputItem, Button, TextareaItem, Toast } from 'antd-mobile'
import HeaderSelector from '../../components/header-selector/header-selector'

import {connect} from 'react-redux'
import { updateUser } from '../../redux/actions'
import {Redirect} from 'react-router-dom'

class Dashen extends Component {

  state = {
    header: '',     // 头像名称 
    post: '',      // 职位
    info: '',     // 个人或职位简介
  }

  // 更新header状态
  setHeader = (header) => {
    this.setState({header})
  }

  save = () => {
    if (!this.state.header) {
      return Toast.info('请选择头像')
    }
    this.props.updateUser(this.state)
  }

  render() {
    const {header, type} = this.props.user
    if (header) {
      const path = type==='dashen'? '/dashen' : '/laoban'
      return <Redirect to={path}/>
    }
    return (
      <div>
        <NavBar>大神信息完善</NavBar>
        <HeaderSelector setHeader={this.setHeader}/>
        <InputItem placeholder='请输入求职岗位' onChange={val =>  this.setState({ post: val }) }>求职岗位</InputItem>
        <TextareaItem rows={3} title='个人介绍' placeholder="请输入个人介绍" onChange={(val) => { this.setState({ info: val }) }}>个人介绍</TextareaItem>
        <Button type='primary' onClick={this.save}>保&nbsp;&nbsp;&nbsp;存</Button>
      </div>
    )
  }
}


export default connect(
  state => ({user: state.user}),
  {updateUser}
)(Dashen)